Waterfill column-width distribution - #3
Merged
Merged
Conversation
Replace the ad-hoc proportional allocator with an analytical waterfill: find the unique level L where sum(min(nat, L·√nat)) equals the budget, then round via Webster/Sainte-Laguë. The old algorithm had binary thresholds for small-column protection and tight-budget fallback that caused columns to shrink when the terminal got wider. The waterfill is monotonic by construction — no column ever loses width when more space becomes available. The min-word-width metric is no longer needed and is removed from compute-table-metrics, which also drops the per-cell longest-word scan. resize-all bench improves ~15% (fewer GC cycles).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the ad-hoc proportional allocator with an analytical waterfill: find the unique level L where
sum(min(nat, L·√nat)) = budget, then round via Webster/Sainte-Laguë.The old algorithm had binary thresholds for small-column protection and tight-budget fallback that caused columns to shrink when the terminal got wider. The waterfill is monotonic by construction — no column ever loses width when more space becomes available.
The cliff
A table with columns
| ID | Name | Category | Description |(natural widths 2, 12, 11, 93) hits a catastrophic discontinuity at width 39. The old algorithm suddenly protects Name and Category at full width, starving Description to 1 character — one letter per line:Before (w=38 → w=39):
After — smooth progression, no column ever shrinks:
Benchmark
resize-allimproves ~15% (fewer GC cycles from dropping the per-cell longest-word scan):Changes
min-word-widthsfromcompute-table-metrics(no longer used)--longest-word-widthhelper and--small-column-thresholdconstant